<template>
    <div class="middle-container" :style="{backgroundImage: bgImg, color: '#38E5DE'}">
        <div class="title-container">
            <div class="title">
                <img src="../../../assets/img/common/title_tip.png" height="16" width="16"/>
                <div class="title-text">{{ title }}</div>
            </div>
            <img src="../../../assets/img/common/close-16px.png" style="cursor: pointer" @click="closeWindow" height="16" width="16"/>
        </div>
        <div class="content-container">
            <world-map id="out-world-map" :data-height="height" :data-width="width"  ref="outWorldMap"/>
        </div>
    </div>
</template>
<script>
import { reactive, toRefs, onMounted, ref, defineComponent } from "vue";
import echartsUtil from "../../../commons/utils/echartsUtil";
import WorldMap from "../../../components/portEconomy/WorldMap";
import http from "@/commons/utils/httpUtil";
import worldData from './wordMap'
export default defineComponent({
    name: 'ColdChain',
    components:{
        WorldMap
    },
    setup() {
        const outWorldMap = ref(null)
        const state = reactive({
        dateRange: [new Date(), new Date()],
        bgImg: 'url(' + require('../../../assets/img/common/middle-bg.png') + ')',
        title: '冷冻品流向图',
        height: 650,
        width:'100%',
      
    }) 
    const closeWindow = () => {
        window.AC.HideWindow(6, {});
    }
   
    const handleSearch = () => {
        console.log(state.dateRange)
    }
    // 获取地图数据并绘制地图
    const getMapData = () => {
        let worldMapData = worldData.records;
        let worldMapOption = {
            titleText: '',
            groupArray: [{
                target: '南山',
                points: worldMapData.map(item => {
                    return {portCode: item.portCode, portName: item.portNameCn}
                }),
                pointsValue: worldMapData.map(item => item.goodsThr.toFixed(2)),
                style: 'to'
            }],
        }
        outWorldMap.value.initOption(worldMapOption)
    }
     /**
         * 初始化世界港口集装箱吞吐量排名
         */
     const initFreGoodsInPortRankingOption = () =>{
            let _this = this;
            http.get('/large/queryFreGoodsInPortRanking/2020/20').then((res) => {
                if (res && res.data && res.data.records.length > 0) {
                    let dataList = res.data.records.filter((item, index) => index < 6);

                    let freGoodsOutPortRankingOption = {
                        // titleText: '班轮航线',
                        legendData: ['2020年吞吐量'],
                        xAxisData: dataList.map(item => item.portNameCn),
                        yAxisName: '吞吐量(万吨)',
                        seriesData: [
                            dataList.map(item => item.goodsThr),
                        ]
                    }

                    _this.$refs.freGoodsIn.initSeries(freGoodsOutPortRankingOption);
                }
            });
        }
    onMounted(()=>{
        // initMap()
        getMapData()
    })
    return {
        outWorldMap,
        ...toRefs(state),
        closeWindow,
        handleSearch,
        initFreGoodsInPortRankingOption
    }
  },
  
})
</script>
<style>
.middle-container {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    height: 800px;
    width: calc(1200px - 48px);
    padding-left: 24px;
    padding-right: 24px;
}

.title-container {
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    height: 46px;
    width: 100%;
    font-size: 18px;
    font-weight: bold;
    border-bottom: 1px solid #38E5ED;
}

.title {
    display: inline-flex;
    align-items: center;
}

.title-text {
    margin-left: 5px;
}
.search-container{
    position: relative;
    color:#fff;
    margin:20px 0;
    text-align: left;
}
.search-btn{
    margin-left: 15px;
    width: 100px;
}
.content-container{
    height: 600px;
    /* overflow-y: scroll; */
}

</style>